<?php
class AppController extends Controller {
	/**
	 * components
	 *
	 * Array of components to load for every controller in the application
	 *
	 * @var $components array
	 * @access public
	 */
	var $uses = array('Group');
	
	var $components = array('Auth', 'P28n');
 	var $helpers = array('Html','Menu');

	function currencyLoad($lang)
	{
		switch($lang)
		{
			case 'por': case 'spa':
				$this->set('currencyValue','1');
				$this->set('currencyName','EUR');
				break;
			case 'eng':
				$this->set('currencyValue','0.898012913');
				$this->set('currencyName','GPB');
				break;
		}
	}


	function beforeRender()
	{
		$this->set('lang',$this->Session->read('Config.language'));
	}

	function refresh($field = '', $value = '') {

		if (!empty($field) && !empty($value)) {
			$this->Session->write($this->sessionKey .'.'. $field,
			$value);

		} elseif ($user =& $this->getModel()) {
			$this->login($user->read(false, $this->user('id')));
		}
	}

	/**
	 * beforeFilter
	 *
	 * Application hook which runs prior to each controller action
	 *
	 * @access public
	 */
	function beforeFilter(){
		//$this->Auth->autoRedirect = false;
		//Override default fields used by Auth component
		$this->Auth->fields = array('username'=>'login','password'=>'password');
		//Set application wide actions which do not require authentication
		$this->Auth->allow(array('*'));
		//Set the default redirect for users who logout
		$this->Auth->logoutRedirect = '/';
		//Set the default redirect for users who login
		$this->Auth->loginRedirect = '/';
		//Extend auth component to include authorisation via isAuthorized action
		$this->Auth->authorize = 'controller';
		//Restrict access to only users with an active account
		$this->Auth->userScope = array('User.active = 1');
		//Pass auth component data over to view files
		$this->set('Auth',$this->Auth->user());


		$this->Admin = true;

		$group = $this->Group->read(null, $this->Auth->user('group_id'));
		if($group['Group']['name']=='Admin')
		{
			$this->Admin = true;
			$this->set('Admin',true);
		}
		else
		{
			$this->Admin = false;
			$this->set('Admin',false);
		}

	}

}

?>